package com.achao.service.impl;

import com.achao.beans.entity.MyMap;
import com.achao.beans.qo.QueryInfoQo;
import com.achao.mapper.MyMapMapper;
import com.achao.service.MyMapService;

import javax.annotation.Resource;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import com.achao.beans.dto.Result;

import java.util.List;

/**
 * (MyMap)表服务实现类
 *
 * @author achao
 * @since 2022-10-18 09:03:09
 */
@Service("myMapService")
public class MyMapServiceImpl implements MyMapService {

    @Resource
    private MyMapMapper myMapMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return Result
     */
    @Override
    public Result queryById(Integer id) {
        MyMap myMap = this.myMapMapper.queryById(id);
        return Result.success("success",myMap);
    }

    /**
     * 新增数据
     *
     * @param myMap 实例对象
     * @return Result
     */
    @Override
    public Result insert(MyMap myMap) {
        int insert = this.myMapMapper.insert(myMap);
        if (insert > 0){
            return Result.success("success");
        }
        return Result.error("error");
    }

    /**
     * 修改数据
     *
     * @param myMap 实例对象
     * @return Result
     */
    @Override
    public Result update(MyMap myMap) {
        int update = this.myMapMapper.update(myMap);
        if (update > 0){
            return Result.success("success",this.queryById(myMap.getId()));
        }
        return Result.error("error");
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return Result
     */
    @Override
    public Result deleteById(Integer id) {
        int delete = this.myMapMapper.deleteById(id);
        if (delete > 0){
            return Result.success("success");
        }
        return Result.error("error");
    }

    @Override
    public Result queryPage(QueryInfoQo queryInfoQo) {
        String str = (String) queryInfoQo.getQueryMap().get("str");
        System.out.println(str);
        Page<Object> page = PageHelper.startPage(queryInfoQo.getPageNumber(), queryInfoQo.getPageSize());
        List<MyMap> myMaps = myMapMapper.queryPage(str);
        System.out.println(page);
        return Result.success("多条件分页查询",myMaps);
    }
}
